package com.lxt.common.util;

import org.apache.commons.codec.binary.Base64;

import java.security.MessageDigest;
import java.sql.Timestamp;

public class MD5Utils {

    /**
     * @Title: MD5Utils.java
     * @Package com.imooc.utils
     * @Description: 对字符串进行md5加密
     */
    public static String getMD5Str24(String strValue) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        String newstr = Base64.encodeBase64String(md5.digest(strValue.getBytes()));
        return newstr;
    }

    public static String getMD5Str32(String strValue) throws Exception {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        int i;
        StringBuffer buf = new StringBuffer("");
        byte b[] = md5.digest();
        for (int offset = 0; offset < b.length; offset++) {
            i = b[offset];
            if (i < 0) {
                i += 256;
            }
            if (i < 16) {
                buf.append("0");
            }
            buf.append(Integer.toHexString(i));
        }

        return buf.toString();
        //String newstr = Base64.encodeBase64String(md5.digest(strValue.getBytes()));
        //return newstr;
    }

    public static void main(String[] args) {
        try {
            String md5 = getMD5Str24("lxt");
            //Timestamp d = new Timestamp(System.currentTimeMillis());
            //String md5 = getMD5Str32("s5UJcSTzf6+WwAYUqb96"+"qEffshJHzLroUFP8ntOmA"+d);
            System.out.println(md5);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
